package com.shiguiwu.springmybatis.javabase.reflect;

import lombok.extern.slf4j.Slf4j;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

/**
 * @description:
 * @author: stone
 * @date: Created by 2022/2/12 19:08
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.reflect
 */
@Slf4j
public class JavaBeanTests {


    public static void main(String[] args) throws IntrospectionException {
        BeanInfo beanInfo = Introspector.getBeanInfo(Student.class);
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

        //System.out.println(Arrays.toString(propertyDescriptors));

        for (PropertyDescriptor descriptor : propertyDescriptors) {

            String name = descriptor.getName();

            Method readMethod = descriptor.getReadMethod();
            Method writeMethod = descriptor.getWriteMethod();

            log.info("属性 {}，get的方法是{}，set的方法是 {}", name, readMethod != null ? readMethod.getName() : "", writeMethod != null ?
                    writeMethod.getName() : "");
        }

    }
}
